﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Startup.Shell.Domain;

namespace Startup.Shell.ModelDesignerPreview
{
	public class PreviewDesignerCtrl
	{
		protected override void OnDragEnter(DragEventArgs e)
		{
			if (!e.Data.GetDataPresent("IDesignerPreview") && !e.Data.GetDataPresent("StartupProperty"))
			{
				e.Effects = DragDropEffects.None;
			}

			base.OnDragEnter(e);
		}

		protected override void OnDrop(DragEventArgs e)
		{
			if (e.Data.GetDataPresent("IDesignerPreview"))
			{
				var preview = (IDesignerPreview)e.Data.GetData("IDesignerPreview");
				PreviewContainer.Preview = preview.CreateInstance();
			}
			else if (e.Data.GetDataPresent("StartupProperty"))
			{
				var propperty = (StartupProperty) e.Data.GetData("StartupProperty");
				PreviewContainer.PropertyId = propperty.Id;
			}

			OnPreviewContainerChanged(this, new DependencyPropertyChangedEventArgs());

			base.OnDrop(e);
		}
	}
}
